﻿using System;
using System.Drawing;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows;
using SUNRPA.CONTROLS.IMPL.util;
using System.Runtime.InteropServices;

namespace RPAVIEW.util {
    public static class ConverterUtil {
        //bitmap转ImageSource
        public static ImageSource Bitmap2ImageSource(this Bitmap bitmap){
            IntPtr hBitmap = bitmap.GetHbitmap();
            ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap,IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions());
            // 记得要进行内存释放。否则会有内存不足的报错。
            GDIUtils.DeleteObject(hBitmap);
            return wpfBitmap;
        }
    }
}
